﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QT.Windows.Shell;

namespace LogAnalytics.Tools
{
    public partial class DataManager : GlassForm
    {
        public DataManager()
        {
            InitializeComponent();
            loadForm();
        }

        private void gbtnMove_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("操作执行后不可以恢复，确认要执行吗？", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return;

            string sitename = this.cbbSiteListinDelete.SelectedValue.ToString();
            if (LogBase.DataManage.MoveRecord(string.IsNullOrEmpty(sitename) ? null : sitename, this.dtpMove.Value.ToString("yyyy-MM-dd")) == -1)
            {
                MessageBox.Show("操作失败");
            }
            else
            {
                MessageBox.Show("操作成功");
            }
        }

        private void gbtnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("操作执行后不可以恢复，确认要执行吗？", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return;

            string sitename = this.cbbSiteListinDelete.SelectedValue.ToString();
            if (LogBase.DataManage.DeleteRecord(string.IsNullOrEmpty(sitename) ? null : sitename, this.dtpDelete.Value.ToString("yyyy-MM-dd")) == -1)
            {
                MessageBox.Show("操作失败");
            }
            else
            {
                MessageBox.Show("操作成功");
            }
        }

        private void gbtnMultiDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("操作执行后不可以恢复，确认要执行吗？", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return;

            string sitename = this.cbbSiteListinDelete.SelectedValue.ToString();
            if (LogBase.DataManage.DeleteMultiRecord(string.IsNullOrEmpty(sitename) ? null : sitename, this.dtpMultiDelStart.Value.ToString("yyyy-MM-dd"), this.dtpMultiDelEnd.Value.ToString("yyyy-MM-dd")) == -1)
            {
                MessageBox.Show("操作失败");
            }
            else
            {
                MessageBox.Show("操作成功");
            }
        }

        private void loadForm()
        {
            DataTable dt = LogBase.SiteManage.getAll();
            DataRow dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "-全部站点-";
            dr[2] = "";
            dr[3] = "";
            dr[4] = true;
            dr[5] = "";
            dt.Rows.InsertAt(dr, 0);


            this.cbbSiteListinMove.DisplayMember = "sitename";
            this.cbbSiteListinMove.ValueMember = "guid";
            this.cbbSiteListinMove.DataSource = dt;


            this.cbbSiteListinDelete.DisplayMember = "sitename";
            this.cbbSiteListinDelete.ValueMember = "guid";
            this.cbbSiteListinDelete.DataSource = dt;

            this.cbbSiteListinMultiDelete.DisplayMember = "sitename";
            this.cbbSiteListinMultiDelete.ValueMember = "guid";
            this.cbbSiteListinMultiDelete.DataSource = dt;
        }
    }
}
